/**
 * 
 */
package com.login.gwj.dao;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.login.gwj.domain.User;

/**
 * @author Administrator
 * 
 */
public class UserDaoImpl implements UserDao {
	@Resource
	private SessionFactory sessionFactory;
	private Query query;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zhbit.bbs.dao.UserDao#insertUser(com.zhbit.bbs.domain.User)
	 */
	

	public User insertUser(User user) {
		sessionFactory.getCurrentSession().persist(user);

		return user;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zhbit.bbs.dao.UserDao#updateUser(com.zhbit.bbs.domain.User)
	 */

	public User updateUser(User user) {
		sessionFactory.getCurrentSession().update(user);
		return user;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zhbit.bbs.dao.UserDao#deleteUser(com.zhbit.bbs.domain.User)
	 */

	public void deleteUser(User user) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().delete(user);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zhbit.bbs.dao.UserDao#selectUser(java.lang.String)
	 */

	public List searchUser(String whereSql,User user) {
		// TODO Auto-generated method stub
		
		query = sessionFactory.getCurrentSession().createQuery(whereSql);
		
		query.setString(0, user.getUserName());
		query.setString(1, user.getPassword());
		List list= query.list();
		System.out.println(list.size());
		return list;
	}

	public List searchUserR(String whereSql, User user) {
		// TODO Auto-generated method stub
		query = sessionFactory.getCurrentSession().createQuery(whereSql);

		query.setString(0, user.getUserName());
		List<User> userlist= query.list();
		System.out.println(userlist.size());
		return userlist;
	}

	public List<User> searchallUser(String string, Timestamp logindata) {
		// TODO Auto-generated method stub
		query = sessionFactory.getCurrentSession().createQuery(string);
		String str=logindata+"";
		String []strs=str.split("[.]");
		query.setString(0, strs[0]);
		List<User> userlist= query.list();
		System.out.println(userlist.size());
		return userlist;
	}

}
